{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "if not any(path.endswith('textbook') for path in sys.path):\n",
    "    sys.path.append(os.path.abspath('../../..'))\n",
    "from textbook_utils import *"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(ch:files)=\n",
    "# Wrangling Files"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before you can work with data in Python, it helps to understand the files that store the source of the data.\n",
    "You want answers to a couple of basic questions:\n",
    "\n",
    "+ How much data do you have?\n",
    "+ How is the source file formatted?\n",
    "\n",
    "Answers to these questions can be very helpful. For example, if your file is too large or is not formatted the way you expect, you might not be able to properly load it into a dataframe."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Although many types of structures can represent data, in this\n",
    "book we primarily work with data tables, such as Pandas DataFrames and SQL\n",
    "relations. (But do note that {numref}`Chapter %s <ch:text>` examines\n",
    "less-structured text data, and {numref}`Chapter %s <ch:web>` introduces\n",
    "hierarchical formats and binary files.) We focus on data tables for several reasons. Research on how to store and manipulate data tables has resulted in\n",
    "stable and efficient tools for working with tables.\n",
    "Plus, data in a tabular format are close\n",
    "cousins of matrices, the mathematical objects of the immensely rich field of\n",
    "linear algebra.\n",
    "And of course, data tables are quite common."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this chapter, we introduce typical file formats and encodings for plain text, describe measures of file size, and use Python tools to examine source files. Later in the chapter, we introduce an alternative approach for working with files: the shell interpreter. Shell commands give us\n",
    "a programmatic way to get information about a file outside the Python\n",
    "environment, and the shell can be very useful with big data. \n",
    "Finally, we check the data table's shape\n",
    "(the number of rows and columns) and granularity\n",
    "(what a row represents).\n",
    "These simple checks are the starting point for cleaning and analyzing our data. "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We first provide brief descriptions of the datasets that we use as examples throughout this chapter."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
